home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Languages / Mops 2.7 / Mops source / System source / FP test < prev    next >
Text File  |  1993-11-04  |  2KB  |  49 lines

  1. \ FP test.
  2. +echo
  3.  
  4. 2.3    fvalue    FV
  5.  
  6. 1.2    fcon    FC
  7.  
  8. \ One way to test our FP ops is to do a number of calculations with
  9. \ with a known result at the end.  The calculations should be simple
  10. \ enough that if we get the wrong answer, we've got a fighting chance
  11. \ of finding where things went wrong.  So here we check that
  12. \ sin**2 (x) + cos**2 (x) = 1.  We square the sine and cos in two
  13. \ different ways and use different operand modes, in the hope that any
  14. \ bugs in the operand accessing will show themselves.  Also extra dummy
  15. \ local variables can be added or removed, to test correct use of the
  16. \ ExtraLocals area versus the D regs and FP regs.
  17.  
  18. : Q  { %angle \ %temp1 %temp2 %temp3 %temp4 %q %q2 %q3 %q4 -- b }
  19.     %angle sin  -> %temp1
  20.     %angle cos  -> %temp2
  21.     %temp1 %temp1 f*  -> %temp3
  22.     %temp2 fdup f* -> %temp4
  23.     %temp3  %temp4  f+
  24.     1.0 f-
  25.     0.000000001 f< if  true  else  false  then  ;
  26.  
  27. : TEST1
  28.     0.2 q  .    room: fltmem  .    ;    \ Should print  -1 100
  29.  
  30.  
  31. \ Here's a timing test:
  32.  
  33. : TEST2  { \ %a %b %c %d -- }
  34.     global ticks @
  35.     100. -> %a  200. -> %b  300. -> %c  400. -> %d
  36.     100000 0 DO
  37.         %a %b f*  %c %d f*  f+
  38.         %a %d f+  f/  -> fv
  39.     LOOP
  40.     global ticks @ - negate .  ."  ticks" cr  fv e.
  41.     3 beep  ;
  42.  
  43. \ The original version of this test (I keep modifying it) took
  44. \ 60 secs. on a IIsi (20 MHz 68030) without FPU.  With FPU, but
  45. \ still using SANE: 45 secs.  (SANE has a lot of overhead.)  With normal
  46. \ run-time FPU detection from Mops: 14.9 secs.  With compiled (optimized)
  47. \ FPU code in Mops: 3.1 secs.  The hand-coded assembly equivalent took
  48. \ 1.5 secs.
  49.